package com.googlecode.cswish.security.auth;


import org.apache.commons.lang.StringUtils;

import com.googlecode.cswish.util.FrameConstant;


/**
 * @author Jerry.Feng Date: 2005-1-25 14:19:47
 * @version $id: $
 */
public class Link {	
	/**
	 * if it's false, we'll make linker valid, else we only display it using a text format 
	 */
	private boolean forbid;
	
	/**
	 * the resource path, it end with ".do"
	 */
	private String actionPath;
	
	/**
	 * the value of formAction
	 */
	private String formActionValue;
	
	/**
	 * the full linker path
	 */
	private String fullPath;
	
	/**
	 * the display name of the linker
	 */
	private String displayName;	
	
	public Link() {		
	}
	
	public Link(String actionPath, String formActionValue, String fullPath, String displayName, boolean forbid) {
		this.actionPath = actionPath;
		this.formActionValue = formActionValue;
		this.fullPath = fullPath;
		this.displayName = displayName;
		this.forbid = forbid;		
	}
	
	public Link(String contextPath, String linkerPathNoContext, String displayName) {		
		int index = StringUtils.indexOf(linkerPathNoContext, '?');
		if (index > 0) {
			actionPath = linkerPathNoContext.substring(0, index);
			
			index = StringUtils.indexOf(linkerPathNoContext, FrameConstant.FORM_ACTION + "=");
			if (index > 0) {
				index += FrameConstant.FORM_ACTION.length() + 1;
				
				int end = StringUtils.indexOf(linkerPathNoContext, '&', index);
				if (end < 0) {
					end = linkerPathNoContext.length();
				}
				formActionValue = linkerPathNoContext.substring(index, end);
			}
		} else {
			actionPath = linkerPathNoContext;		
		}
		
		fullPath = contextPath + linkerPathNoContext;
	}
	
	public String getActionPath() {
		return actionPath;
	}
	public void setActionPath(String actionPath) {
		this.actionPath = actionPath;
	}
	public String getDisplayName() {
		return displayName;
	}
	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}	
	public boolean getForbid() {
		return forbid;
	}
	public void setForbid(boolean forbid) {
		this.forbid = forbid;
	}
	public String getFormActionValue() {
		return formActionValue;
	}
	public void setFormActionValue(String formActionValue) {
		this.formActionValue = formActionValue;
	}	
	public String getFullPath() {
		return fullPath;
	}
	public void setFullPath(String fullPath) {
		this.fullPath = fullPath;
	}
}
